<template>
  <div>
    <nav-bar>
      <div slot="left" class="back" @click="backHome">
        <img src="@/assets/img/common/back.svg" alt />
      </div>
      <div slot="center" class="nav-bar">
        <div
          v-for="(item, index) in titles"
          :key="item"
          class="item-bar"
          @click="itemClick(index)"
          :class="{active: index === currentIndex}"
        >{{item}}</div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from '@/components/common/navbar/NavBar'

export default {
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ['商品', '评论', '参数', '推荐'],
      currentIndex: 0,
    }
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index
      this.$emit('titleClick', index)
    },
    backHome() {
      this.$router.back()
    },
  },
}
</script>

<style scoped>
.nav-bar {
  display: flex;
  font-size: 13px;
}
.item-bar {
  flex: 1;
}
.active {
  color: var(--color-high-text);
}
.back img {
  vertical-align: middle;
}
</style>